#!/bin/bash

# 颜色定义
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color

echo -e "${YELLOW}开始运行HTML解析器测试...${NC}"

# 保存当前目录
CURRENT_DIR=$(pwd)
# 进入脚本所在目录
cd "$(dirname "$0")"

# 编译运行程序
echo -e "${YELLOW}编译测试程序...${NC}"
cargo build --bin run_tests

if [ $? -ne 0 ]; then
    echo -e "${RED}编译失败!${NC}"
    exit 1
fi

# 运行测试
echo -e "${YELLOW}运行测试...${NC}"
./target/debug/run_tests

# 检查运行结果
if [ $? -eq 0 ]; then
    echo -e "${GREEN}所有测试通过!${NC}"
else
    echo -e "${RED}测试失败!${NC}"
    cd "$CURRENT_DIR"
    exit 1
fi

# 返回原目录
cd "$CURRENT_DIR"

echo -e "${YELLOW}测试完成.${NC}"
